//package com.weixin.engine.lemeng;
//
//import cn.hutool.core.codec.Base64;
//import com.nhsoft.neptune.sdk.config.ApiCloudConfig;
//import com.nhsoft.neptune.sdk.dto.TokenResponseDTO;
//import com.nhsoft.neptune.sdk.httpclient.AuthFeign;
//import com.nhsoft.neptune.sdk.util.CacheUtil;
//import com.weixin.engine.sss.pojo.LmToken;
//import com.weixin.engine.sss.service.ILmTokenService;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.scheduling.annotation.EnableScheduling;
//import org.springframework.scheduling.annotation.Scheduled;
//import org.springframework.stereotype.Component;
//
//import javax.annotation.Resource;
//import java.util.List;
//
///**
// * 定时刷新乐檬token
// *
// * @author wangchunhui
// * @date 2023/6/6 15:37
// */
//@Slf4j
//@EnableScheduling
//@Component
//public class RefreshTokenJob {
//
//    @Resource
//    private ILmTokenService lmTokenService;
//
////    @Resource
////    private AuthFeign authFeign;
//
//    /**
//     * 每隔30分钟刷新一次token
//     */
//    @Scheduled(fixedDelay = 1000 * 60 * 30)
//    public void refreshToken() {
//        log.info(Thread.currentThread().getName() + ": 定时任务开始刷新token");
//        List<LmToken> lmTokens = lmTokenService.list();
//        lmTokens.forEach(this::refreshToken);
//        log.info(Thread.currentThread().getName() + ": 定时任务结束刷新token");
//    }
//
//    private void refreshToken(LmToken lmToken) {
////        String credential = "Basic ".concat(Base64.encode(ApiCloudConfig.getAppId().concat(":").concat(ApiCloudConfig.getAppSecret())));
////        TokenResponseDTO tokenResponseDTO = authFeign.getTokenByRefreshToken(credential, lmToken.getRefreshToken());
////        lmToken.setAccessToken(tokenResponseDTO.getAccessToken());
////        lmToken.setRefreshToken(tokenResponseDTO.getRefreshToken());
////        lmTokenService.updateById(lmToken);
////        CacheUtil.setToken(lmToken.getSystemBookCode(), tokenResponseDTO.getAccessToken(), tokenResponseDTO.getRefreshToken());
////        log.info("账套号 {} 刷新token成功", lmToken.getSystemBookCode());
//    }
//}
